# fingerprint database
#

class Fingerprint:
    x = 0
    y = 0
    rssi = []

    def __init__(self, raw_data):
        datas = raw_data.split('\t')
        self.x = float(datas[0])
        self.y = float(datas[1])
        self.rssi = []
        num = int(datas[2])
        for i in range(num):
            index = i * 2 + 3
            self.rssi.append(float(datas[index]))

    def __str__(self):
        # show fingerprint (outFile)
        out_string = '{0}\t{1}\t{2}'.format(self.x, self.y, len(self.rssi))
        num_rssi = len(self.rssi)
        for i in range(num_rssi):
            out_string = out_string + '\t{0}\t1.0'.format(self.rssi[i])
        return out_string


class FingerprintDatabase:
    fingerprint_num = 0
    apList = []
    fingerprints = []

    def __init__(self, FileDir):
        # input mac address
        in_file = open(FileDir + '\\apList.txt', 'r')
        lines = in_file.readlines()
        for line in lines:
            mac = line[:-1]
            self.apList.append(mac)
            in_file.close()
            self.fingerprint_num += 1

        # input fingerprint
        in_file = open(FileDir + '\\fingerprints.txt', 'r')
        lines = in_file.readlines()
        for line in lines:
            self.fingerprints.append(Fingerprint(line))

        for fp in self.fingerprints:
            print(str(fp))
        in_file.close()

    def get_index(self, mac_address):
        for index, mac in enumerate(self.apList):
            if mac == mac_address:
                return index
        return None